package com.sctvcloud.bazhong.ui.adapter.holder;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.ruihang.generalibrary.ui.adapter.holder.BaseRecylerHolder;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.ruihang.generalibrary.utils.DateUtils;
import com.sctvcloud.bazhong.R;
import com.sctvcloud.bazhong.beans.ChatItem;
import com.sctvcloud.bazhong.ui.utils.GlideCircleTransform;
import com.sctvcloud.bazhong.ui.utils.GlideUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by rh008 on 2017/7/27.
 */

public class ChatHolder extends BaseRecylerHolder<ChatItem> {
    @BindView(R.id.item_chat_icon)
    protected ImageView icon;
    @BindView(R.id.item_chat_name)
    protected CustomFontTextView name;
    @BindView(R.id.item_chat_time)
    protected CustomFontTextView time;
    @BindView(R.id.item_chat_msg)
    protected CustomFontTextView msg;

    public ChatHolder(Context context, View itemView) {
        super(context, itemView);
    }

    @Override
    protected void initInject() {
        ButterKnife.bind(this, itemView);
    }

    @Override
    public void setData(ChatItem chat) {
        name.setText(!TextUtils.isEmpty(chat.getUserName()) ? chat.getUserName() : "");
        msg.setText(!TextUtils.isEmpty(chat.getChatContent()) ? chat.getChatContent() : "");
        if (TextUtils.isEmpty(chat.getUserIcon())) {
            icon.setImageResource(R.drawable.circle_bl);
        } else {
            GlideUtil.getGlideWithAvatorDef(context, chat.getUserIcon()).error(R.mipmap.icon_circle_avatar)
                    .placeholder(R.mipmap.icon_circle_avatar).transform(new GlideCircleTransform(context)).into(icon);
        }
        time.setText(!TextUtils.isEmpty(chat.getPubTime()) ? DateUtils.timeAgo(DateUtils.getDataDate(chat)) : "");
    }
}
